/* 
 * File:	main.c
 * Authors: Johan Dahlberg <S102591>
 *				Daniel Jansson <S102496>
 * ---------------------------------
 * Task 2:
 */
#include "genlib.h"
#include "simpio.h"

/* Prototypes */
/*
 * Function: IsMeasureable
 * Usage: bool = IsMeasureable(target, weights, nWeights)
 * -----------------
 * Check if Measureable
 */
bool IsMeasureable(int target, int weights[], int nWeights);

/* Variables */
static int sampleWeights[] = {1, 3};
static int nSampleWeights = 2;

/* Code */

main() {
	int i,nTargets = 0,sample;
	bool test;
	int targets[10];

	printf("Give available weights, finish with -1\n");
	
	for(i = 0; i < 10; i++){
		targets[i] = GetInteger();
		nTargets++;

		if(targets[i] == -1) {
			break;
		}
	}
	
	for(i = 0; i < nTargets-1; i++){
		if(IsMeasureable(targets[i], sampleWeights, nSampleWeights) == TRUE) {
			printf("%d is measureable\n",targets[i]);
		} else {
			printf("%d is NOT measureable\n",targets[i]);
		}
	}

	getchar();
}

bool IsMeasureable(int target, int weights[], int nWeights) {
	if(target < 0) {
		return FALSE;
	} else if(target == 0) {
		return TRUE;
	} else if (IsMeasureable(target - weights[nWeights - 1], weights, nWeights - 1)) {
		return TRUE;
	}

	return FALSE;
}